import updateManager from './common/updateManager';
import i18nInstance from "./miniprogram_npm/miniprogram-i18n-plus/index"
import locales from "./config/locales"
App({
  onLaunch: function () {
    this.login()
    const lang = wx.getStorageSync('lang')
    if (lang == null || lang == "") {
      i18nInstance.setLocale("zh_CN");
      wx.setStorageSync('lang', "zh_CN")
    }
    else {
      i18nInstance.setLocale(lang);

    }
    i18nInstance.loadTranslations(locales);
  },
  onShow: function () {
    updateManager();
  },
  login: function () {
    // wx.login()获取code
    wx.login({
      success: (res) => {
        console.log("code: " + res.code);
        wx.setStorageSync('code', res.code)
        wx.request({
          url: 'http://127.0.0.1:8080/login',
          method: 'POST',
          data: {
            code: res.code
          },
          success(e) {
            console.log(e.data.openid);
            wx.setStorageSync('openid', e.data.openid)
          }
        })
      }
    })
  },

});
